﻿#include "EditorCPUTimeAnalyzePageView.h"
#include "EditorCPUTimeAnalyzePageViewModel.h"

#include "Widgets/Mouse/MouseWidget.h"
#include "Widgets/TextWidget.h"
#include "Widgets/ButtonWidget.h"
#include "Widgets/Positioners/HorizontalPositionerWidget.h"
#include "Widgets/EditorImageButton.h"
#include "Widgets/EditorTextButton.h"

void REditorCPUTimeAnalyzePageView::BindViewModel(TSharedObjectPtr<REditorPageViewModel> InViewModel)
{
    //Super::BindViewModel(InViewModel);
    ViewModel = InViewModel;
}

void REditorCPUTimeAnalyzePageView::CreateWidget(TSharedObjectPtr<RWidget> InParent)
{
    auto Root= NewWidget<RWidget>(InParent);
    Root->Anchor.Fill(InParent);

    const float ButtonSize=30.f;
    const float ButtonSpacing=10.f;
    auto Buttons= NewWidget<RHorizontalPositionerWidget>(Root);
    Buttons->Anchor.CenterIn(Root);
    Buttons->Height=ButtonSize;
    Buttons->Width=ButtonSize *2+ButtonSpacing;
    Buttons->Spacing=ButtonSpacing;

    // auto Test= NewWidget<RRectangleWidget>(Root);
    // Test->Anchor.Fill(InParent);
    // Test->FillColor=SColor(1,0,0,1);

    //添加两个按钮，分别是开始、停止
    auto StartButton=WHE::CreateTextButton(
        U"开始"
        , [this]()
        {
            ViewModel->Start();
            return true;
        }
        ,Buttons
    );
    StartButton->Width=ButtonSize;
    StartButton->Height=ButtonSize;
   
    auto StopButton= WHE::CreateTextButton(
        U"停止"
        , [this]()
        {
            ViewModel->Stop();
            return true;
        }
        ,Buttons
    );

    StopButton->Width=ButtonSize;
    StopButton->Height=ButtonSize;
  
    auto StateText= NewWidget<RTextWidget>(Root);
    StateText->Anchor.TopReference=Buttons;
    StateText->Anchor.TopReferenceEdge=EVerticalWidgetEdge::Bottom;
    StateText->Anchor.TopOffset=10;
    StateText->Anchor.LeftReference=Buttons;
    StateText->Text=[this]()
    {
        return ViewModel->GetStateText();
    };

    auto Text= NewWidget<RTextWidget>(Root);
    Text->Anchor.BottomReference=Root;
    Text->Height=100;
    Text->Anchor.LeftReference=Root;
    Text->HorizontalAlignment=ETextHorizontalAlignment::Center;
    Text->Text=U"该页面尚未完成，仅提供简单的操作按钮";

}
